package com.gz.interceptor;

import cn.jiguang.common.ClientConfig;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.PushPayload;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
 * Created by gongzhen on 2018/6/4.
 */
public class AdminInterceptor implements Interceptor{



    @Override
    public void intercept(Invocation inv) {
        Controller controller=inv.getController();
        String token=controller.getRequest().getHeader("Authorization");
        System.out.println(token);

    }


    public static PushPayload buildPushObject_all_all_alert() {
        return PushPayload.alertAll("test");
    }

    public static void main(String[] args) {
        JPushClient jpushClient = new JPushClient("24235fb6cf7dad4a833b1c5f","0f61f9f4ebc68527998bc851", null, ClientConfig.getInstance());

        // For push, all you need do is to build PushPayload object.
        PushPayload payload = buildPushObject_all_all_alert();

        try {
            PushResult result = jpushClient.sendPush(payload);
            System.out.printf(""+result.statusCode);
        } catch (APIConnectionException e) {
            // Connection error, should retry later

        } catch (APIRequestException e) {
            // Should review the error, and fix the request

        }
    }
}
